import request from '@/utils/request';

// 定义日志相关接口的类型
export interface Log {
  log_id?: number;
  user_id?: number;
  level?: string;
  message: string;
  tag?: string;
  ip_address?: string;
  user_agent?: string;
  request_url?: string;
  request_method?: string;
  createdAt?: string;
  updatedAt?: string;
  user_info?: {
    user_id: number;
    account: string;
    name: string;
    avatar?: string;
  };
}

export interface LogListParams {
  page?: number;
  limit?: number;
  level?: string;
  tag?: string;
  keyword?: string;
  sort_field?: string;
  sort_order?: string;
}

export interface LogDetailParams {
  log_id: number;
}

export interface DeleteLogParams {
  log_id: number;
}

export interface BatchDeleteLogsParams {
  log_ids: number[];
}

// 获取日志列表
export const getLogList = (data: LogListParams) => {
  return request.post<{ list: Log[]; pagination: any }>('/log/list', data);
};

// 获取日志详情
export const getLogDetail = (data: LogDetailParams) => {
  return request.post<Log>('/log/detail', data);
};

// 删除日志
export const deleteLog = (data: DeleteLogParams) => {
  return request.post('/log/delete', data);
};

// 批量删除日志
export const batchDeleteLogs = (data: BatchDeleteLogsParams) => {
  return request.post('/log/batch-delete', data);
};

// 清空日志
export const clearLogs = () => {
  return request.post('/log/clear');
};

// 获取日志统计信息
export const getLogStatistics = () => {
  return request.post('/log/statistics');
};